package com.yoso.definition;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyUserBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("myUser")) {
            System.out.println("5.BeanPostProcessor,对象:" + beanName + ",在调用初始化(afterPropertiesSet)之前的数据:" + bean.toString());
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("myUser")) {
            System.out.println("8.BeanPostProcessor,对象:" + beanName + ",在调用初始化(initMethod)之后的数据:" + bean.toString());
        }
        return bean;
    }
}

